import 'package:flutter/material.dart';
import 'package:flutter_taotaoshipin/pages/me/me_routes.dart';
import 'package:flutter_taotaoshipin/util/global.dart';
import 'package:flutter_taotaoshipin/value/constant.dart';
import 'package:flutter_taotaoshipin/widget/load_image.dart';
import 'package:flutter_taotaoshipin/widget/my_app_bar.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher_string.dart';

class AboutMePage extends StatelessWidget {
  const AboutMePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: '关于我们',
      ),
      body: CustomScrollView(
        slivers: [
          SliverPadding(
            padding: EdgeInsets.symmetric(horizontal: 17, vertical: 20),
            sliver: DecoratedSliver(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(8),
              ),
              sliver: SliverList.list(
                children: [
                  _buildItem(
                    '用户协议',
                    onTap: () {
                      Global.openUserProtocol();
                    },
                  ),
                  _buildItem(
                    '隐私政策',
                    onTap: () {
                      Global.openPravicyPolicy();
                    },
                  ),
                  _buildItem(
                    '苹果最终用户协议（EULA）',
                    onTap: () {
                      Global.openAppleEULA();
                    },
                  ),
                  _buildItem(
                    '版本更新',
                    onTap: () {
                      launchUrlString(
                          'https://apps.apple.com/cn/app/id${Constant.appstoreId}');
                    },
                  ),
                  _buildItem(
                    '注销帐号',
                    onTap: () {
                      Get.toNamed(MeRoutes.logoutAccount);
                    },
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  _buildItem(String title, {Function()? onTap}) {
    return GestureDetector(
      onTap: onTap,
      child: Stack(
        children: [
          Container(
            width: double.infinity,
            height: 55,
            padding: EdgeInsets.symmetric(horizontal: 17),
            child: Row(
              children: [
                Expanded(
                  child: Text(
                    title,
                    style: TextStyle(
                      color: Color(0xFF333333),
                      fontSize: 16,
                    ),
                  ),
                ),
                LoadAssetImage(
                  'me/arrow_right',
                  width: 11,
                  height: 11,
                ),
              ],
            ),
          ),
          Positioned(
            child: Divider(
              indent: 17,
              endIndent: 17,
              color: Color(0xFFEBEFF7),
              height: 0.5,
            ),
          ),
        ],
      ),
    );
  }
}
